import moment from "moment";
const formatSessionDate = (timestamp) => {
  const timestampTime = moment(timestamp).locale("zh-cn");
  const now = moment();
  const daysDiff = now.diff(timestampTime, "days");

  if (daysDiff === 0) {
    return timestampTime.format("HH:mm");
  } else if (daysDiff === 1) {
    return "昨天";
  } else if (daysDiff < 7) {
    return timestampTime.format("dddd");
  } else {
    return timestampTime.format("YY-MM-DD");
  }
};

const formatMessageDate = (timestamp) => {
  const timestampTime = moment(timestamp).locale("zh-cn");
  const now = moment();
  const daysDiff = now.diff(timestampTime, "days");
  const currentYear = now.year();
  const messageYear = timestampTime.year();

  if (daysDiff === 0) {
    return timestampTime.format("HH:mm");
  } else if (daysDiff === 1) {
    return `昨天 ${timestampTime.format("HH:mm")}`;
  } else if (daysDiff < 7) {
    return `${timestampTime.format("dddd")} ${timestampTime.format("HH:mm")}`;
  } else if (messageYear === currentYear) {
    return timestampTime.format("MM-DD HH:mm");
  } else {
    return timestampTime.format("YY-MM-DD HH:mm");
  }
};

const formatCreateDate = (timestamp) => {
  const timestampTime = moment(timestamp).locale("zh-cn");
  return timestampTime.format("YY-MM-DD HH:mm");
};

export { formatSessionDate, formatMessageDate, formatCreateDate };
